
**** report descriptive statistics 

set more off

use Data/Andrea/Interval_prices.dta, clear

keep account_number read_date daily_charge

duplicates drop 


merge 1:m account_number read_date using Data/Andrea/sample_income_discountoc_angle.dta, 

keep if _merge == 3
drop _merge


drop hour_*


merge 1:1 account_number read_date hour using Data/Andrea/sample_map.dta, 

drop _merge 

keep if hhhour_sample ==1

gen hourly_fixed = (daily_charge/24)*(1-discount)


replace export = 0 if hour <= 5 | hour >=20

* just calculate ghi for 9-5pm
replace ghi = . if hour <9 | hour>17
replace virtualincome =. if hour<9 | hour>17


gen fullretailcost = peakoffpeak_price * consumption
gen net_hourly_cost =  (peakoffpeak_price * importkWh) - (discount_FIT * exportkWh ) // both discounted
gen hourly_bill =  net_hourly_cost + hourly_fixed

gen weekly_inc = virtualincome_dis 


* want average FIT paid per kWh of export
replace FIT_price = pexport_FIT if FIT_t=="S" 
replace FIT_price =. if pexport_FIT== 0 & FIT_t =="S"

gen not_NS= streetangle~=3


collapse  (firstnm) firstdate= read_date (lastnm) lastdate= read_date (firstnm) not_NS priceplan discount product_code max_solaroutput feedin* metertype zone* solar_size FIT_t FIT_price distributor latitude longitude Melbourne Geelong Mornington Country SA1 (mean) virtualincome  peak_price off_peak_price exportkWh importkWh consumption_kWh PV_productionkWh temp_interp ghi weekly_inc  hourly_bill fullretailcost, by(account_number)


replace weekly_inc = (weekly_inc* 24*7 )/100
gen weekly_bill = (hourly_bill * 24*7)/100
gen weekly_fullretail = (fullretailcost * 24*7)/100


tab metertype, gen(TOU)
drop TOU2

replace feedin1 = 1-feedin1
replace feedin2 = 1-feedin2
replace feedin3 = 1-feedin3
replace feedin4 = 1-feedin4

gen feedorder = 1 if FIT_t =="S"
replace feedorder = 2 if FIT_t =="P"
replace feedorder = 3 if FIT_t =="T"
replace feedorder = 4 if FIT_t =="F"

label define feedorder 1 "S" 2 "P" 3 "T" 4 "F" 
label values feedorder feedorder

label variable not_NS "Street angle"
label variable discount "Plan discount"
label variable weekly_bill "Bill ($/week)"

*** Descriptive statistics
***********************
eststo clear
estpost tabstat FIT_price peak_price off_peak_price discount importkWh exportkWh weekly_bill temp_interp ghi  Melbourne not_NS consumption_kWh PV_productionkWh solar_size virtualincome weekly_inc, ///
by(feedorder) statistics(mean sd) columns(statistics) listwise  // columns(statistics) 

esttab using Results/Andrea/desc_stats.tex , main(mean) aux(sd) nostar  unstack  replace title("Descriptive statistics")


tab feedorder 
